package com.healthy.support.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.healthy.common.log.annotation.Log;
import com.healthy.common.log.enums.BusinessType;
import com.healthy.common.security.annotation.RequiresPermissions;
import com.healthy.support.domain.Messages;
import com.healthy.support.service.IMessagesService;
import com.healthy.common.core.web.controller.BaseController;
import com.healthy.common.core.web.domain.AjaxResult;
import com.healthy.common.core.utils.poi.ExcelUtil;
import com.healthy.common.core.web.page.TableDataInfo;

/**
 * 聊天内容Controller
 * 
 * @author 束伟
 * @date 2024-03-29
 */
@RestController
@RequestMapping("/Messages")
public class MessagesController extends BaseController
{
    @Autowired
    private IMessagesService messagesService;

    /**
     * 查询聊天内容列表
     */
    @RequiresPermissions("support:Messages:list")
    @GetMapping("/list")
    public TableDataInfo list(Messages messages)
    {
        startPage();
        List<Messages> list = messagesService.selectMessagesList(messages);
        return getDataTable(list);
    }

    /**
     * 导出聊天内容列表
     */
    @RequiresPermissions("support:Messages:export")
    @Log(title = "聊天内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Messages messages)
    {
        List<Messages> list = messagesService.selectMessagesList(messages);
        ExcelUtil<Messages> util = new ExcelUtil<Messages>(Messages.class);
        util.exportExcel(response, list, "聊天内容数据");
    }

    /**
     * 获取聊天内容详细信息
     */
    @RequiresPermissions("support:Messages:query")
    @GetMapping(value = "/{messageId}")
    public AjaxResult getInfo(@PathVariable("messageId") Long messageId)
    {
        return success(messagesService.selectMessagesByMessageId(messageId));
    }

    /**
     * 新增聊天内容
     */
    @RequiresPermissions("support:Messages:add")
    @Log(title = "聊天内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Messages messages)
    {
        return toAjax(messagesService.insertMessages(messages));
    }

    /**
     * 修改聊天内容
     */
    @RequiresPermissions("support:Messages:edit")
    @Log(title = "聊天内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Messages messages)
    {
        return toAjax(messagesService.updateMessages(messages));
    }

    /**
     * 删除聊天内容
     */
    @RequiresPermissions("support:Messages:remove")
    @Log(title = "聊天内容", businessType = BusinessType.DELETE)
	@DeleteMapping("/{messageIds}")
    public AjaxResult remove(@PathVariable Long[] messageIds)
    {
        return toAjax(messagesService.deleteMessagesByMessageIds(messageIds));
    }
}
